class Site::InfoController < ApplicationController
  
  def index
    @title = "创意资讯"
    @newests = Info.find(:all, :limit => 20, :order => "updated_at DESC") # newest infos
    @businesses = Info.find_less_infos(1) # business infos
    @competitions = Info.find_less_infos(2) # competition infos
    @exhibitions = Info.find_less_infos(3) # exhibition infos
    @campuses = Info.find_less_infos(4) # campus infos
    @sugs = Info.find(:all, :limit => 5, :order => "updated_at DESC") # suggest infos
    @works = Work.find(:all, :limit => 6, :order => "click_times DESC, work_comments_count DESC") # works for suggest
    @requirements = Requirement.find(:all, :limit => 10, :order => "click_times DESC, comments_count DESC") # suggested requirements
  end
  
  def show
    @info = Info.find(params[:id])
    @title = "创意资讯-#{@info.title}"
    @infos = @info.infotype.infos.find(:all, :order => "created_at DESC", :conditions => "id!='#{@info.id}'")
    @works = Work.find(:all, :limit => 6, :order => "click_times DESC, work_comments_count DESC") # works for suggest
    @requirements = Requirement.find(:all, :limit => 10, :order => "click_times DESC, comments_count DESC") # suggested requirements
  end
  
  def detail
    id = params[:id]
    if !id.nil?
      @infotype = Infotype.find(id)
      @title = "#{@infotype.name}"
      @infos = @infotype.infos.paginate(:page => params[:page], :per_page => PERPAGE, :order => "updated_at DESC")
    else
      @title = "所有资讯"
      @infos = Info.paginate(:page => params[:page], :per_page => PERPAGE, :order => "updated_at DESC")
    end
  end

end
